/*
 * @(#)ShopVideoServiceImpl.java 2012-01-13
 *
 * Copyright 2011 北龙中网（北京）科技有限责任公司. All rights reserved.
 */
package cn.shangjia.shop.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.shangjia.common.dao.support.Page;
import cn.shangjia.common.domain.audit.ShopVideo;
import cn.shangjia.common.domain.support.State;
import cn.shangjia.common.util.StringUtils;
import cn.shangjia.shop.config.Constants;
import cn.shangjia.shop.dao.ShopVideoDao;
import cn.shangjia.shop.service.ShopVideoService;
import cn.shangjia.shop.service.impl.common.CommonService;

/**
 * 商铺视频实现
 *
 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
 * @version 1.0, 2012-01-13 10:36:46
 * @since 1.0
 */
@Service
public class ShopVideoServiceImpl implements ShopVideoService {
	
	@Resource 
	private ShopVideoDao shopVideoDao;
	
	@Resource
	private CommonService commonService;
	
	@Override
	public ShopVideo getShopVideo(String id) {
		if (StringUtils.isEmpty(id))
			return null;
		return shopVideoDao.read(id);
	}

	@Override
	public Page<ShopVideo> findShopVideoPage(String userId, int pageNo,int pageSize) {
        Page<ShopVideo> page = new Page<ShopVideo>();
		if (StringUtils.isEmpty(userId)) return page;
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		Map<String, Object> parames = new HashMap<String, Object>();
		parames.put("userId", userId);
		
		//jinzhognze 判断 是否是vip
		boolean flag = commonService.isVip(userId) 
									? Constants.siteSetting.getVipVideoVerifyFlag().booleanValue()
									: Constants.siteSetting.getUserVideoVerifyFlag().booleanValue();
		
		if(flag){
			//先审后发
			parames.put("auditStatus", State.PASS);
		}else{
			//先发后审
			parames.put("auditStatusPass", State.PASS);
			parames.put("auditStatusAuditing", State.AUDITING);
		}
		page.setTotalCount(shopVideoDao.totalCount(parames));

		return shopVideoDao.selectListPage(page , parames);
	}

}
